import os
import sys
from typing import List, Set

def scan_imports(root_path: str, base_package: str) -> List[str]:
    imports: Set[str] = set()
    base_package_prefix = base_package + "."
    for dirpath, _, filenames in os.walk(root_path):
        for filename in filenames:
            if filename.endswith('.java'):
                file_path = os.path.join(dirpath, filename)
                with open(file_path, 'r', encoding='utf-8') as f:
                    for line in f:
                        line = line.strip()
                        if line.startswith('import '):
                            import_stmt = line[len('import '):].rstrip(';')
                            import_stmt = import_stmt.strip()
                            # 只处理普通import，不处理static import
                            if import_stmt.startswith('static '):
                                continue
                            # 过滤本包下的import
                            if import_stmt.startswith(base_package_prefix):
                                continue
                            imports.add(import_stmt)
    return sorted(imports)

def main():
    if len(sys.argv) != 3:
        print("用法: python WorkflowScan.py <包绝对路径> <包路径>")
        print("示例: python WorkflowScan.py c:/code/ddd-sample/src/main/java/com/huawei/service com.huawei.service")
        sys.exit(1)
    root_path = sys.argv[1]
    base_package = sys.argv[2]
    result = scan_imports(root_path, base_package)
    print("\n".join(result))

if __name__ == "__main__":
    main() 